package cn.burnit.view;


import cn.burnit.pojo.Reader;
import cn.burnit.service.ReaderService;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 查询用户个人信息
 */
public class CheckPersonInfoForm extends JFrame {

    private JLabel title,readerName,readerType,sex,max_num,days_num;
    private JTextField checkReaderNameField,readerNameField,readerTypeField,sexField,max_numField,days_numField;
    private JButton close,check;

    public CheckPersonInfoForm() {

        Container container = getContentPane();
        container.setLayout(null);

        check=new JButton("查询");
        check.setBounds(270,60,60,20);
        close=new JButton("关闭");
        close.setBounds(180,340,60,20);
        close.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
        check.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                search(e);
            }
        });


        title=new JLabel("个人信息");
        title.setFont(new Font("宋体", Font.PLAIN, 24));
        title.setBounds(170,10,200,25);
        readerName=new JLabel("读者名称:");
        readerName.setFont(new Font("宋体", Font.PLAIN, 16));
        readerName.setBounds(130,100,100,20);
        readerType=new JLabel("读者类型:");
        readerType.setFont(new Font("宋体", Font.PLAIN, 16));
        readerType.setBounds(130,140,100,20);
        sex=new JLabel("性别:");
        sex.setFont(new Font("宋体", Font.PLAIN, 16));
        sex.setBounds(162,180,100,20);
        max_num=new JLabel("最大可借数量:");
        max_num.setFont(new Font("宋体", Font.PLAIN, 16));
        max_num.setBounds(100,220,150,20);
        days_num=new JLabel("最大可借天数:");
        days_num.setFont(new Font("宋体", Font.PLAIN, 16));
        days_num.setBounds(100,260,150,20);


        //搜索框
        checkReaderNameField=new JTextField();
        checkReaderNameField.setBounds(150,60,130,20);

        readerNameField=new JTextField();
        readerNameField.setEditable(false);
        readerNameField.setBounds(220,100,130,20);
        readerTypeField=new JTextField();
        readerTypeField.setEditable(false);
        readerTypeField.setBounds(220,140,130,20);
        sexField=new JTextField();
        sexField.setEditable(false);
        sexField.setBounds(220,180,130,20);
        max_numField=new JTextField();
        max_numField.setEditable(false);
        max_numField.setBounds(220,220,130,20);
        days_numField=new JTextField();
        days_numField.setEditable(false);
        days_numField.setBounds(220,260,130,20);

        container.add(title);
        container.add(checkReaderNameField);container.add(check);
        container.add(readerName);container.add(readerNameField);
        container.add(readerType);container.add(readerTypeField);
        container.add(sex);container.add(sexField);
        container.add(max_num);container.add(max_numField);
        container.add(days_num);container.add(days_numField);
        container.add(close);



        setTitle("个人信息");
        setSize(470,470);
        setLocationRelativeTo(null);
        setResizable(false);
        setVisible(true);
        //setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    private void search(ActionEvent e) {
        String readername = this.checkReaderNameField.getText();
        ReaderService readerService = new ReaderService();
        Reader reader = readerService.serch(readername);
        if (reader!=null){
            this.readerNameField.setText(reader.getReadername());
            this.readerTypeField.setText(reader.getReadertype());
            this.sexField.setText(reader.getSex());
            this.max_numField.setText(String.valueOf(reader.getMax_num()));
            this.days_numField.setText(String.valueOf(reader.getDays_num()));
        }
    }


//    public static void main(String[] args) {
//        new CheckPersonInfoForm();
//    }


}
